package com.qinggeng.project.system.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.qinggeng.common.enums.PrintStatusEnum;
import com.qinggeng.framework.aspectj.lang.annotation.Excel;
import com.qinggeng.framework.web.domain.BaseEntity;
import com.qinggeng.project.api.dto.AddOrdersInfoDto;
import com.qinggeng.project.tool.pay.utils.PayUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 订单列对象 orders
 *
 * @author qinggeng
 * @date 2020-06-17
 */
@Data
public class Orders extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** ID */
    private Long ordersId;

    /** 订单编号 */
    @Excel(name = "订单编号")
    private String ordersNo;
    /**订单类型 10=普通订单 20=免费送 30=拼团订单 40=批发专区 50=捶一捶*/
    @Excel(name = "订单类型 10=普通订单 20=免费送 30=拼团订单 40=批发专区 50=捶一捶")
    private String ordersType;

    /** 支付状态 10未支付20已支付 */
    @Excel(name = "支付状态 10未支付20已支付")
    private String payStatus;

    /** 支付时间 */
    @Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date payTime;

    /** 支付超时时间 */
    @Excel(name = "支付超时时间", width = 30, dateFormat = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date payOutTime;

    /** 商品总价 */
    @Excel(name = "商品总价")
    private BigDecimal totalPrice;

    /** 优惠价格 */
    @Excel(name = "优惠价格")
    private BigDecimal reducePrice;

    /** 配送方式 10=配送 20=自取 */
    @Excel(name = "配送方式 10=配送 20=自取")
    private String distType;

    /** 配送费 */
    @Excel(name = "配送费")
    private BigDecimal distPrice;

    /** 配送时间 */
    @Excel(name = "配送时间")
    private String distTime;

    /** 取货时间 */
    @Excel(name = "取货时间")
    private String pickTime;


    /** 预留手机号 */
    @Excel(name = "预留手机号")
    private String pickPhone;

    /** 合计支付 */
    @Excel(name = "合计支付")
    private BigDecimal payPrice;

    /** 退款金额 */
    @Excel(name = "退款金额")
    private BigDecimal payment;

    /** 支付类型  wxpay 微信支付 alipay 支付宝 */
    @Excel(name = "支付类型  wxpay 微信支付 alipay 支付宝")
    private String payType;

    /** 用户ID */
    @Excel(name = "用户ID")
    private Long userId;

    /** 店铺ID */
    @Excel(name = "店铺ID")
    private Long shopId;

    /** 删除标志（0代表存在 2代表删除） */
    private String delFlag;

    /** 状态 10=进行中,20=取消,30=已完成,40=已关闭 50=退单中 60=已退单 70=退单失败*/
    @Excel(name = "状态 10=进行中,20=取消,30=已完成,40=已关闭 50=退单中 60=已退单 70=退单失败")
    private String status;

    /** 店铺接单状态 10=待店铺接单 20=店铺接单 30=店铺拒绝 */
    @Excel(name = "店铺接单状态 10=待店铺接单 20=店铺接单 30=店铺拒绝")
    private String distShopStatus;

    /** 店铺操作时间 */
    @Excel(name = "店铺操作时间")
    private Date distShopTime;

    /** 店铺操作描述 */
    @Excel(name = "店铺操作描述")
    private String distShopDesc;

    /** 支付超时时间 */
    @Excel(name = "店铺接单超时时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date distShopOutTime;

    /** 配送状态 10=等待配送员接单 20=等待配送员取货 30=配送中 40=已送达 */
    @Excel(name = "配送状态 10=等待配送员接单 20=等待配送员取货 30=配送中 40=已送达")
    private String distStatus;

    /** 接单时间 */
    @Excel(name = "接单时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date distTime10;

    /** 取货时间 */
    @Excel(name = "取货时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date distTime20;

    /** 送达时间 */
    @Excel(name = "送达时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date distTime30;


    /** 送达时间 */
    @Excel(name = "配送接单超时时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date distOutTime;

    /** 发货状态 10=待发货,20=已发货 */
    @Excel(name = "发货状态 10=待发货,20=已发货")
    private String shipStatus;

    /** 发货时间 */
    @Excel(name = "发货时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date shipTime;

    @Excel(name = "自动确认收货时间", width = 30, dateFormat = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date affirmOutTime;

    @Excel(name = "确认收货时间", width = 30, dateFormat = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date affirmTime;

    @Excel(name = "评价状态 10=未评价,20=已评价")
    private String evalStatus;

    @Excel(name = "评价时间", width = 30, dateFormat = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date evalTime;

    @Excel(name = "评价超时时间", width = 30, dateFormat = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date evalOutTime;

    private Date cancelTime;

    private String cancelRemark;

    private Integer ordersIndex;

    /**
     * 商品列表
     */
    private List<OrdersGoods> goodsList;

    /**
     * 奖品列表
     */
    private List<OrdersGift> giftList;


    /**
     * 收货地址
     */
    private OrdersAddress ordersAddress;

    /**
     * 配送点
     */
    private OrdersPoint ordersPoint;

    /**
     * 配送员
     */
    private OrdersCourier courier;
    /**
     * 签收人姓名
     */
    private String receiver;

    /**
     * 打印状态（10=未打印 20=已打印）
     */
    private String printStatus;

    /**
     * 店铺
     */
    private Shop shop;

    private Date distDateTime;

    //订单特点 '单商品下单'=1  '拼团下单'=2
    private String ordersCharacter;

    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private Long pointId;

    public Orders() {
    }

    public Orders(AddOrdersInfoDto ordersInfoDto) {
        this.ordersNo=PayUtils.getOrderCode();
        this.ordersType=ordersInfoDto.getOrdersType();

        this.distPrice=ordersInfoDto.getDistPrice();
        this.pickPhone=ordersInfoDto.getPickPhone();
        this.payPrice=ordersInfoDto.getPayPrice();
        this.totalPrice=ordersInfoDto.getTotalPrice();
        this.reducePrice=ordersInfoDto.getReducePrice();
        this.shopId=ordersInfoDto.getShop().getId();
        this.setRemark(ordersInfoDto.getRemark());
        this.pickTime=ordersInfoDto.getPickTime();
        this.distTime=ordersInfoDto.getDistTime();
        this.distDateTime=ordersInfoDto.getDistDateTime();
        this.printStatus= PrintStatusEnum.不可打印.getStatus();
    }




    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("ordersId", getOrdersId())
            .append("ordersNo", getOrdersNo())
            .append("payStatus", getPayStatus())
            .append("payTime", getPayTime())
            .append("payOutTime", getPayOutTime())
            .append("totalPrice", getTotalPrice())
            .append("distType", getDistType())
            .append("distPrice", getDistPrice())
            .append("distTime", getDistTime())
            .append("pickTime", getPickTime())
            .append("payPrice", getPayPrice())
            .append("payType", getPayType())
            .append("userId", getUserId())
            .append("shopId", getShopId())
            .append("delFlag", getDelFlag())
            .append("createTime", getCreateTime())
            .append("updateTime", getUpdateTime())
            .append("remark", getRemark())
            .append("status", getStatus())
            .append("distShopStatus", getDistShopStatus())
            .append("distShopTime", getDistShopTime())
            .append("distShopDesc", getDistShopDesc())
            .append("distStatus", getDistStatus())
            .append("distTime10", getDistTime10())
            .append("distTime20", getDistTime20())
            .append("distTime30", getDistTime30())
            .append("shipStatus", getShipStatus())
            .append("shipTime", getShipTime())
                .append("affirmTime",getAffirmTime())
                .append("receiver",getReceiver())
                .append("printStatus",getPrintStatus())
            .toString();
    }
}
